package com.ljx.List;

import com.ljx.Dynamic.ListNode;

/**
 * @author 李加喜
 * @Package com.ljx.List
 * @date 2021-11-06 10:53
 */
// 判断链表是否成环
public class ListRing {
    public static void main(String[] args) {

    }
    public boolean hasCycle(ListNode head) {
        ListNode slow=head,first=head;
        while (first!=null && first.next!=null){
            slow=slow.next;
            first=first.next.next;
            if (slow==first){
                return true;
            }
        }
        return false;
    }
}
